package com.allenkerr.controller;

import com.allenkerr.client.TestClient;
import com.allenkerr.model.Person;
import com.allenkerr.service.StaticInfoService;
import com.allenkerr.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by 小柯(Allen Kerr) on 17.6.25 00:31.
 */
@RestController
@RequestMapping(value = "/static", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class StaticInfoController {

    @Autowired
    private StaticInfoService staticInfoService;

    @GetMapping("/people")
    public List<Person> getPeople() {
        return staticInfoService.getPeople();
    }

    @GetMapping("/people/id/{id}")
    public Person getPersonById(@PathVariable Integer id) {
        return staticInfoService.getPersonById(id);
    }

    //=================================== Test Patch ====================================

    @PatchMapping("/test/{id}")
    public Result test(@PathVariable Integer id) {
        return Result.success("ID: " + id);
    }

    @Autowired
    private TestClient testClient;

    @PatchMapping("/test-patch/{id}")
    public Result testPatch(@PathVariable Integer id) {
        Result result = testClient.test(id);
        result.setData("测试成功！");
        return result;
    }

}
